<template>
  <div :class="{ navBar1: true, fixedNav: isFixed }">
    <!-- <HeaderTop :title="title" :backUrl="'/loan'"></HeaderTop> -->
    <HeaderTop :title="title"></HeaderTop>
    <!-- <div class="tips-wrap">
      <img src="~@/assets/imgs/information/notice.png" alt="">
      <p class="tips">*is required</p>
    </div> -->
    <div class="menu" ref="menu">
      <div class="menu-progress-wrap">
        <van-progress text-color="transparent" :percentage="progressValue" color="#EC5958" class="menu-progress" :class="{ step1: progressValue === 0, step100: progressValue === 100 }"/>
      </div>
      <ul class="menu-title">
        <li :class="{ 'active': position === 'identity' || status.identity }">Identity</li>
        <li :class="{ 'active': position === 'personal' || status.personal }">Personal</li>
        <li :class="{ 'active': position === 'work' || status.work }">Work</li>
        <li :class="{ 'active': position === 'contact' || status.contact }">Contact</li>
        <li :class="{ 'active': position === 'additional' || status.additional }">Additional</li>
      </ul>
    </div>
    <div v-if="!isFixed" class="tips" ref="tips">
      <p>{{ $t('informationTips') }}</p>
    </div>
  </div>
</template>

<script>
import { Dialog, Progress } from 'vant';
import HeaderTop from '@/components/header-top'

export default {
  name: 'navBar',
  components: {
    HeaderTop,
    [Progress.name]: Progress
  },
  props: {
    position: {
      type: String,
      default: ''
    },
    status: {
      type: Object,
      default: {}
    },
  },
  data() {
    return {
      productId: '',
      btnType: '',
      readonly: '',
      instalment: false,
      isFixed: false,
      progressValue: 0,
      title: ''
    };
  },
  methods: {
    goInfomation(url) {
      const path = '/information/' + url;
      if (this.readonly && this.btnType === 'save') {
        this.$router.push({
          path,
          query: { productId: this.productId, readonly: 'true', btnType: 'save' }
        });
      } else if (!this.readonly && this.btnType === 'save') {
        this.$router.push({
          path,
          query: { productId: this.productId, btnType: 'save' }
        });
      } else if (this.instalment) {
        this.$router.push({
          path,
          query: { instalment: 'true' }
        });
      } else {
        this.$router.push({
          path,
          query: { productId: this.productId }
        });
      }
    },
    handleFixedTab() {
      const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
      if (scrollTop > 0) {
        this.isFixed = true;
      } else {
        this.isFixed = false;
      }
    },
    setProgress (step) {
      this.progressValue = 100 * (step / 8)
    }
  },
  created() {
    if (this.position == 'identity') {
      this.title = 'Identity Information'
    };
    if (this.position == 'work') {
      this.title = 'Work Information'
      this.setProgress(3.6)
    };
    if (this.position == 'contact') {
      this.title = 'Contact'
      this.setProgress(5.5)
    };
    if (this.position == 'additional') {
      this.title = 'Additional Information'
      this.setProgress(8)
    };
    if (this.position == 'personal') {
      this.title = 'Personal Information'
      this.setProgress(2)
    };
    const query = this.$route.query;
    this.productId = query.productId;
    this.btnType = query.btnType;
    this.readonly = (query.readonly === 'true');
    this.instalment = (query.instalment === 'true');
    document.addEventListener('scroll', this.handleFixedTab, false);
    window.scroll(0, 0); // 强制页面加载时滚动条到顶部
  }
};
</script>

<style lang="scss">
@import "~@/assets/scss/function";

@font-face {
  font-family: DINALTERNATE;
  src: url('~@/assets/SF-Pro-Display-Bold.otf');
}

.navBar1 {
  width: 100%;
  margin: 0 auto;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 16;
  padding: 98px 40px 0;
  background: linear-gradient( 180deg, #FDEFB5 0%, #F5F5F5 100%);

  .tips-wrap {
    padding: 0 24px;
    line-height: 62px;
    margin: 0 32px;
    background: transparent;
    border-radius: 28px;
    display: flex;
    align-items: center;

    img {
      width: 32px;
      height: 32px;
    }

    .tips {
      font-size: 24px;
      color: $infoTipsText;
      width: 100%;
      margin-left: 4px;
      border-radius: 12px;

      p {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }

  .menu {
    width: 100%;
    padding: 62px 0 32px;
    background:transparent;
    &-progress {
      width: 100%;
      height: 20px;
      background-color: rgba(#72A9FC, .2) !important;
      border-radius: 10px;
      .van-progress__pivot {
        padding: 0 !important;
        width: 52px !important;
        height: 52px !important;
        background-color: transparent;
        background: url('~@/assets/imgs/navbar_step.png') no-repeat !important;
        // background-size: 100% 100% !important;
        background-size: cover !important;
        transform: translate(0%, -50%) !important;
        font-size: 0;
      }
      &.step1 {
        .van-progress__pivot {
          transform: translate(-10px, -50%) !important;
        }
      }
      &.step100 {
        .van-progress__pivot {
          transform: translate(10px, -50%) !important;
        }
      }
    }
    &-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #C9C9C9;
      font-size: 24px;
      margin-top: 32px;
      & > li {
        &.active {
          color: #EC5958;
        }
      }
    }
  }
}
@media all and (max-width: 340px) {
  .navBar {
    .tips {
      font-size: 18px;
    }
  }
}

.fixedNav {
  position: fixed;
}

.tips {
  color: #EC5958;
  font-size: 24px;
  line-height: 36px;
}
</style>
